package week_three.day02;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class DBcpTest {
	public static void main(String[] args) throws Exception {
		BasicDataSource ds = new BasicDataSource();
		ds.setUrl("jdbc:oracle:thin:@ZHA-ITA092-w7:1522:orcl");
		ds.setDriverClassName("oracle.jdbc.OracleDriver");
		ds.setUsername("evan");
		ds.setPassword("123");
		ds.setMaxActive(2);
		final Connection con1 = ds.getConnection();
		System.out.println(con1);
		Connection con2 = ds.getConnection();
		System.out.println(con2);
		new Thread(){
			@Override
			public void run() {
				try {
					Thread.sleep(2000);
					con1.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}.start();
		Connection con3 = ds.getConnection();
		System.out.println(con3);
//		con.close();//只是扔回池，并没有关闭
	}
}
